package com.zhangxin.aiInterview.manager.redis.audio_emotion;

import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;

/**
 * 音频情感数据删除服务
 */
@Component
public class DeleteAudioEmotion {

    @Resource
    private StringRedisTemplate stringRedisTemplate;

    /**
     * 删除用户的所有音频情感数据
     * @param userId 用户ID
     */
    public void deleteAllEmotions(Long userId) {
        try {
            String key = getKey(userId);
            stringRedisTemplate.delete(key);
        } catch (Exception e) {
            System.out.println("Redis删除音频情感数据失败: " + e.getMessage());
        }
    }

    /**
     * 删除指定数量的最新数据
     * @param userId 用户ID
     * @param count 要删除的数量
     */
    public void deleteLatestEmotions(Long userId, long count) {
        try {
            String key = getKey(userId);
            stringRedisTemplate.opsForList().trim(key, 0, -count-1);
        } catch (Exception e) {
            System.out.println("Redis删除最新音频情感数据失败: " + e.getMessage());
        }
    }

    private String getKey(Long userId) {
        return "AI_interview:audioEmotion:" + userId;
    }
}